<script setup lang="ts">
import ConsultItem from './ConsultItem.vue'
import { ConsultType } from '@/enums'
import { getConsultList } from '@/services/consult'
import { ref } from 'vue'
import type { ConsultOrderItem } from '@/types/consult'

// 接收问诊类型
defineProps<{
  type: ConsultType
}>()

// 问诊订单列表数据
const list = ref<ConsultOrderItem[]>([])
const current = ref(1)

// 获取文章订单数据
const loadConsultList = async () => {
  const res = await getConsultList({
    current: current.value,
    pageSize: 10,
    type: ConsultType.Fast
  })
  // 页数加一
  current.value++
  // 结束加载中状态
  loading.value = false
  // 数据累加
  list.value.push(...res.data.rows)
  // 处理加载完成的逻辑
  if (current.value > res.data.pageTotal) {
    finished.value = true
  }
}

const loading = ref(false)
const finished = ref(false)
const onLoad = () => {
  loadConsultList()
}

// 删除订单
const onDelete = (id: string) => {
  list.value = list.value.filter((item) => item.id !== id)
}
</script>

<template>
  <div class="consult-list">
    <van-list
      v-model:loading="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <consult-item
        v-for="item in list"
        :key="item.id"
        :item="item"
        @on-delete="onDelete"
      ></consult-item>
    </van-list>
  </div>
</template>

<style lang="scss" scoped>
.consult-list {
  padding: 10px 15px;
}
</style>
